package com.hui.web.servlet.roomServlet;

import com.hui.bean.RecordBean;
import com.hui.service.IRecordService;
import com.hui.service.impl.RecordServiceImpl;
import com.hui.util.DateUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet(name = "RoomRecordAddExecuteServlet",urlPatterns = "/room/record/add/execute")
public class RoomRecordAddExecuteServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String date = request.getParameter("date");
        String msg = request.getParameter("msg");
        String roomId = request.getParameter("roomId");
        Date dateTime = DateUtils.strToDate(date);
        RecordBean recordBean = new RecordBean(msg,dateTime);
        IRecordService recordService=new RecordServiceImpl();
        recordService.addRecord(recordBean,Integer.parseInt(roomId));
        response.sendRedirect("/room/record/index?roomId="+roomId);

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
